<template>
  <el-header>
    <div class="left">
      <el-icon @click="handleCollapsed"><Menu /></el-icon>
      <span style="margin-left: 10px">企业门户网站管理系统</span>
    </div>

    <div class="right">
      <span>欢迎 {{ userStore.userInfo.user_name }} 回来</span>
      <el-dropdown>
        <span class="el-dropdown-link">
          <el-icon :size="30"><User /></el-icon>
        </span>
        <template #dropdown>
          <el-dropdown-menu>
            <el-dropdown-item @click="handleCenter">个人中心</el-dropdown-item>
            <el-dropdown-item @click="handleLogout">退出</el-dropdown-item>
          </el-dropdown-menu>
        </template>
      </el-dropdown>
    </div>
  </el-header>
</template>

<script setup lang="js" name="">
import { useCollapsedStore } from "@/stores/uiStore";
import { useUserStore } from "@/stores/userStore";
import { Menu, User } from "@element-plus/icons-vue";
import { useRouter } from "vue-router";
const collapsedStore = useCollapsedStore();
const userStore = useUserStore();
const router = useRouter();

const handleCollapsed = () => {
  collapsedStore.isCollapsed = !collapsedStore.isCollapsed;
};

const handleCenter = () => {
  router.push("/center");
};
const handleLogout = () => {
  localStorage.removeItem("token");
  userStore.userInfo = {}
  router.push("/login");
};
</script>

<style scoped>
.el-header {
  background-color: #2d3a4b;
  color: white;
  width: 100%;
  height: 60px;
  line-height: 60px;
  justify-content: space-between;
  align-items: center;
  display: flex;
}
.left {
  i {
    margin: auto;
    cursor: pointer;
  }
}
.right {
  .el-dropdown {
    margin: 15px;
    cursor: pointer;
  }
}
</style>
